<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>EASY后台-登录</title>
    <link rel="icon" th:href="@{/static/images/favicon.ico}">
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
</head>
<body>
<style>
    body {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        margin: 0;
        /*background: radial-gradient(circle, #6fccbe 0%, #486081 100%);*/
        background: radial-gradient(circle at top left, #63b3a8, transparent),
        radial-gradient(circle at bottom right, #4f76a8, transparent);
        /*background-image: url("./static/images/bg.jpg");*/
        /*background-repeat: no-repeat;*/
        /*background-size: cover;*/
        /*background-position: center;*/
    }

    .login-container {
        width: 420px;
        background-color: #fff;
        box-shadow: 0 3px 6px -1px rgba(0, 0, 0, 0.19);
        box-sizing: border-box;
        border-radius: 5px;
    }

    .login-title {
        height: 40px;
        line-height: 40px;
        text-align: center;
        margin: 20px 0 40px 0;
    }

    .login-title > img {
        height: 44px;
        vertical-align: top;
        border-style: none;
    }

    .login-title > span {
        font-size: 30px;
        color: rgba(0, 0, 0, .85);
        font-family: Avenir, Helvetica Neue, Arial, Helvetica, sans-serif;
        font-weight: 600;
        position: relative;
        top: 2px;
    }

    .login-main {
        margin: 30px;
    }
</style>
<div class="login-container">
    <div class="login-title">
        <img th:src="@{/static/images/logo.png}">
        <span>OZO-EASY</span>
    </div>
    <form class="layui-form">
        <div class="login-main">
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-username"></i>
                    </div>
                    <input type="text" name="username" value="" lay-verify="required" placeholder="用户名" lay-reqtext="请输入用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-password"></i>
                    </div>
                    <input type="password" name="password" value="" lay-verify="required" placeholder="密  码" lay-reqtext="请输入密码" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-input-wrap layui-col-xs9">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-vercode"></i>
                        </div>
                        <input style="width: 97%;" type="text" name="captcha" value="" lay-verify="required" placeholder="验证码" lay-reqtext="请输入验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                    <div class="layui-col-xs3">
                        <img id="captcha" width="100%" height="38" src="/auth/captcha" onclick="this.src='/auth/captcha?_t=' + new Date().getTime();">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="rememberMe" value="true" lay-skin="primary" title="记住我">
                <a href="/register" style="float: right; margin-top: 7px;">注册帐号</a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登录</button>
            </div>
        </div>
    </form>
</div>

<script th:src="@{/static/layui/layui.js}"></script>
<script>
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.$;

        // 提交事件
        form.on('submit(login)', function (data) {
            var field = data.field;
            if (field.username == '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (field.password == '') {
                layer.msg('密码不能为空');
                return false;
            }
            if (field.captcha == '') {
                layer.msg('验证码不能为空');
                return false;
            }

            $.ajax({
                type: 'POST',
                url: '/auth/login',
                dataType: "JSON",
                data: JSON.stringify(field),
                contentType: "application/json",
                success: function (res) {
                    if (res.code === 200) {
                        layer.msg('登录成功', {time: 1000}, function () {
                            window.location = '/index';
                        });
                    } else {
                        layer.msg(res.msg);
                        $("#captcha").click();
                    }
                }
            })

            return false;
        });
    });
</script>

</body>
</html>